package com.ebupt.migu.music.schedule;

import com.ebupt.migu.music.schedule.service.PopupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.ParseException;

/**
 * Created by Intellij IDEA.
 * User:  liuyangyang@cd.ebupt.com
 * Date:  2019/10/30
 */
@Slf4j
@Component
@EnableScheduling
public class PopupTask {

    @Autowired
    private PopupService popupService;

    /**
     * 弹窗策略： 立即弹窗
     * 每分钟执行一次定时任务
     */
    @Scheduled(cron = "${cron.pop_now}")
    public void popupNow() {
        log.info("弹窗策略【立即弹窗】定时任务启动");
        popupService.popupNow();
        log.info("弹窗策略【立即弹窗】定时任务结束");
    }

    /**
     * 弹窗策略： 单次弹窗
     * 每五分钟执行一次定时任务
     */
    @Scheduled(cron = "${cron.pop_once}")
    public void popupOnce() {
        log.info("弹窗策略【单次弹窗】定时任务启动");
        popupService.popupOnce();
        log.info("弹窗策略【单次弹窗】定时任务结束");
    }

    /**
     * 弹窗策略： 策略周期内重复执行弹窗策略
     * 每五分钟执行一次定时任务
     */
    @Scheduled(cron = "${cron.pop_loop}")
    public void popupLoop() throws ParseException {
        log.info("弹窗策略【循环弹窗】定时任务启动");
        popupService.popupLoop();
        log.info("弹窗策略【循环弹窗】定时任务结束");
    }
}
